package com.sg.business.model.contentprovider;

import java.util.ArrayList;
import java.util.List;

import com.sg.business.model.IACLClient;
import com.sg.business.model.PermissionExtendsionTest;
import com.sg.widgets.registry.config.TreeConfigurator;
import com.sg.widgets.viewer.RelationContentProvider;

public class SubFolderContentProvider extends RelationContentProvider {

	private boolean skip;

	public SubFolderContentProvider() {
	}

	public SubFolderContentProvider(TreeConfigurator configurator) {
		super(configurator);
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		Object[] children = super.getChildren(parentElement);
		if(skip){
			return children;
		}
		List<Object> result = new ArrayList<Object>();
		for (int i = 0; i < children.length; i++) {
			boolean ret = PermissionExtendsionTest.test(children[i],
					IACLClient.CODE_QUERY);
			if (ret) {
				result.add(children[i]);
			}
		}

		return result.toArray();
	}

	public void setSkipPermission(boolean skip) {
		this.skip = skip;
	}

}
